/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.admin.forms;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author thaidacvinh
 */
public class AddLeagueStrutsActionForm extends org.apache.struts.action.ActionForm {
    
    private int year;
    private String season;
    private String title;
    private String yearStr;

    /**
     *
     */
    public AddLeagueStrutsActionForm() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * This is the action called from the Struts framework.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    @Override
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        
        // Perform data conversions and verify form parameters
        try {
            if (yearStr.length() != 0) {
                year = Integer.parseInt(yearStr);
                if ((year < 2003) || (year > 2012)) {
                    errors.add("yearStr", new ActionMessage("error.admin.add_league.yearField.range"));
                }        
            } else {
                errors.add("yearStr", new ActionMessage("error.admin.add_league.yearField.required"));
            }
        } catch (NumberFormatException nfe) {
            errors.add("yearStr", new ActionMessage("error.admin.add_league.yearField.format"));
            System.err.println(nfe);
        }
        if (season.equals("UNKNOWN")) {
            errors.add("season", new ActionMessage("error.admin.add_league.seasonField.required"));
        }
        if (title.length() == 0) {
            errors.add("title", new ActionMessage("error.admin.add_league.titleField.required"));
        }
        
        //Return the errors list.  An empty list tells Struts that this form passed the verification check.
        return errors;
    }

    /**
     * @return the year
     */
    public int getYear() {
        return year;
    }

    /**
     * @return the season
     */
    public String getSeason() {
        return season;
    }

    /**
     * @param season the season to set
     */
    public void setSeason(String season) {
        this.season = season;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * @return the yearStr
     */
    public String getYearStr() {
        return yearStr;
    }

    /**
     * @param yearStr the yearStr to set
     */
    public void setYearStr(String yearStr) {
        this.yearStr = yearStr;
    }
}
